# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
from typing import List


class Solution:
    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
        l1_val = self.get_list(l1)
        l2_val = self.get_list(l2)
        ret = l1_val + l2_val

        return self.list_to_node(str(ret))

    def get_list(self,l):
        val = ""
        while l:
            val = f"{l.val}{val}"
            l = l.next
        return int(val)

    def list_to_node(self,l:List):
        dummy = ListNode()
        cur = dummy

        for i in l:
            cur.next = ListNode(i)
            cur = cur.next

        return dummy